<?php

namespace App\Providers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

        $keyWords = env('OS_NAME');
        $description = env('OS_NAME');
        $companyName = env('OS_NAME');
        $menuTitle = env('OS_NAME');
        $thanks = env('OS_NAME');
        View::share(compact('keyWords','description','companyName','menuTitle','thanks'));
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if(env('LOG_IS_SQL',false)){
            //过于复杂的sql这个地方会报错，可以适当注释
            DB::listen(function ($query)  {
                $sql = vsprintf(str_replace('?', '"%s"', $query->sql), $query->bindings);
                Log::channel('sql')->info($sql,['time'=>$query->time]);
            });
        }
    }
}
